#@curdLayout()
#define main()
<script type="text/javascript">
	$(function(){
		var index = parent.layer.getFrameIndex(window.name); ###获取窗口索引
		$("#btn_close").bind("click",function(){
			parent.layer.close(index);
		});
		$("#btn_save").bind("click",function(){
			var zTree = $.fn.zTree.getZTreeObj("zTree");
			var nodes = zTree.getCheckedNodes();
			parent.#(replace(index,"_",""))_opentree = nodes;
			var ids = "";
			var names = "";
			for (var i=0, l=nodes.length; i<l; i++) {
				#if(like(type,"dict_"))
					ids += "," + nodes[i].num;
				#else
					ids += "," + nodes[i].id;
				#end
				names += "," + nodes[i].name;
			}
			ids = ids.substring(1);
			names = names.substring(1);
			
			/* if(ids.length == 0){
				layer.msg("选项不能为空", {shift: 6});
				return false;
			} */

			var _pobj = parent.$("##(index??)").attr("name");
			if (_pobj != undefined){
				var _name = _pobj.replace("token_", "");
				parent.$("##(index??)").attr("name", _name);
				parent.$("#form_token").val(1);
			}
			
			parent.$("##(index??)_INPUT").val(names);
			parent.$("##(index??)").val(ids);
			parent.layer.close(index);
		
		});
		initZtree();
		var winH = $(window).height();
		$("#treeBody").css({"height":winH-100,"overflow-y":"scroll"})
	});
	
	function initZtree(){
		var setting = {
				#if(async=="true")
					async: {
		                enable: true, 
		                url:"#(url??'/ztree/getTreeListAsync')", 
		                autoParam:["id", "pid","level","#(extfield??)"], 
		                otherParam:  {"source":"#(source??)", "type":"#(type??)","where":"#(where??'')","val":"#(val??)","initParam":"#(initParam??'')"},
		                type: 'post',
		                dataFilter:filter
		             },
				#end
				check: {
					enable: true,
					#if(check == "radio")
						chkStyle: "radio",
						radioType : "all"
					#else
						chkboxType :{ "Y" : "#(Y??'')", "N" : "#(N??'')" }
					#end
				},
				data: {
					key:{
				          isParent: "isparent",
				    },
					simpleData: {
						enable: true,
						idKey:'id',
						pIdKey: "pid"
					}
				},
				callback: {
					#if(async=="true")
					onAsyncSuccess: zTree_zTreeOnAsyncSuccess,
					#end
				}
			};
		
		#if(async=="true")
			$.fn.zTree.init($("#zTree"), setting);
			#if(search=="true")
				fuzzySearch("zTree","#zTree_search",null,false);
			#end
		#else
			$.post("/ztree/getTreeList",{source:"#(source??)", type:"#(type??)", where:"#(where??'')", intercept:"#(x.intercept??)", ext:"#(x.ext??)", val:"#(val??)"},function(data){
				if(data.state=='ok'){
					var ztree = $.fn.zTree.init($("#zTree"), setting, data.data);
					#if(search=="true")
						fuzzySearch("zTree","#zTree_search",null,false);
					#end
					var node =  ztree.getNodeByParam('level', 0);
					ztree.expandNode(node, true, false, true);
				}
				else{
					layer.msg('数据加载失败!', {icon: 5});
				}
			}, "json");
		#end
	}
	

	function filter(treeId, parentNode, childNodes) {
	    return childNodes;
	}
	
	function zTree_zTreeOnAsyncSuccess(event, treeId, treeNode, msg) {
		
	};
	
</script>


	<!-- 配置grid -->
	<div class="row">
		<div class="col-sm-1"></div>
		
	    <div class="col-sm-10">
			<div class="widget-box">
				<div class="widget-header">
					<h4 class="widget-title lighter smaller">#(decodeUrl(name??))</h4>
				</div>

				<div class="widget-body">
				    #if(search=="true")
					<div class="input-group input-group-sm" style="padding:10px;">
			                <input id="zTree_search" type="text" class="form-control">
			                    <span class="input-group-btn">
			                      <button type="button" class="btn btn-info btn-flat">搜索</button>
			                    </span>
			                </input>
			       	</div>
			       	#end
					<div id="treeBody"  class="widget-main padding-8">
						<ul id="zTree" class="ztree"></ul>
					</div>
				</div>
			</div>
		</div>
		<div style="text-align:center;position:fixed;bottom:5px;width:100%;">
			  	<button class="btn btn-sm btn-info" type="button" id="btn_save">
					<i class="ace-icon fa fa-check bigger-110"></i>
					确定
				</button>
				&nbsp; &nbsp; &nbsp;
				<button class="btn btn-sm" type="button" id="btn_close">
					<i class="ace-icon fa fa-close bigger-110"></i>
					关闭
				</button>
		</div>
	</div>
	<!-- 引入所需js -->
	<link rel="stylesheet" href="/static/zTree/css/metroStyle/metroStyle.css" />
	<script src="/static/zTree/js/jquery.ztree.core.js" type="text/javascript" ></script>
	<script src="/static/zTree/js/jquery.ztree.excheck.min.js" type="text/javascript" ></script>
	<script src="/static/zTree/js/jquery.ztree.exhide.min.js" type="text/javascript" ></script>
	<script src="/static/zTree/js/fuzzysearch.js" type="text/javascript" ></script>
#end